package xyz.yq56.easytool.utils.date;

import java.util.Date;

import lombok.extern.slf4j.Slf4j;

/**
 * @author yi qiang
 * @date 2021/9/17 0:45
 */
@Slf4j
public class DateFormatUtil {

    private DateFormatUtil() {
    }

    public static String dateToStr(Date date) {
        return dateToStr(date, "yyyy-MM-dd HH:mm:ss");
    }

    public static String dateToStr(Date date, String pattern) {
        return DateFormatter.formatter(pattern).format(date);
    }

    public static Date strToDate(String str) {
        return strToDate(str,null);
    }

    public static Date strToDate(String str, String pattern) {
        Date parse = null;
        try {
            parse = DateFormatter.formatter(pattern).parse(str);
        } catch (Exception e) {
            log.error("DateFormatter | StrToDate Failed: {}",e.getMessage(),e);
        }
        return parse;
    }

}
